package com.usian.service.impl;

import com.usian.mapper.UserMapper;
import com.usian.pojo.User;
import com.usian.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public Integer toLogin(User user) {
        Integer login = userMapper.toLogin(user);// code = 1 查询到一条->登录成功；
        if (login==1){
            return 1;
        }
        return 0;
    }

    @Override
    public Integer toRegister(User user) {
        //先做查询，看账号名称和密码 是否重名
        Integer integer = userMapper.toCompare(user);// code = 1 查询到一条 -- 重名，不能注册；
        if (integer!=1){//
            user.setCreateTime(new Date());
            userMapper.insertUser(user);
            return 1;//成功
        }
        return 0;//失败
    }

    @Override
    public User findByUserName(String userName) {
        return userMapper.findByUserName(userName);
    }
}
